﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SGP;
using System.Xml.Linq;

namespace RoBHERT_TileTool
{
    public partial class Form1 : Form
    {
        public bool run = true;

        /* Tile Types are:
           floor = 1
           door = 3
           wall = 2
           spawnpoint = 4
        */

        string workspace;

        int tilesetpicture = -1;
        Rectangle rect;

        List<Point> positon = new List<Point>();
        List<int> tileTypes = new List<int>();
        List<int> tileRoomNumbers = new List<int>();
        List<Rectangle> tileRec = new List<Rectangle>();
        List<string> tileGraphics = new List<string>();
        List<Point> tileLeftTop = new List<Point>();

        Point MapSize;
        Point MapPixel;
        Point TileSize;
        Point TilePixel;
        string graphicString = "";
        int left = 0;
        int top = 0;

        int currentTileType;
        Point currentPositon;

        int totalRooms;
        List<int> roomNumber = new List<int>();
        List<int> roomRating = new List<int>();

        public Form1()
        {
            InitializeComponent();

            SGP.ManagedDirect3D.Instance.InitManagedDirect3D(panel2, true);
            SGP.ManagedDirect3D.Instance.InitManagedDirect3D(panel1, true);
            SGP.ManagedTextureManager.Instance.InitManagedTextureManager(SGP.ManagedDirect3D.Instance.Device, SGP.ManagedDirect3D.Instance.Sprite);

            // Set the floor as default tile
            Floor.Enabled = false;
            currentTileType = 1;

            // Set Default map
            MapSize.X = 10;
            MapSize.Y = 10;
            MapPixel.X = 32;
            MapPixel.Y = 32;

            MapSize.X = MapSize.X * MapPixel.X;
            MapSize.Y = MapSize.Y * MapPixel.Y;

            mapwidthbox.Value = MapSize.X;
            mapheightbox.Value = MapSize.Y;
            mappixelsbox.Value = MapPixel.X;
            mappixelbox2.Value = MapPixel.Y;

            panel2.Invalidate();

            // Set Default tile
            TileSize.X = 4;
            TileSize.Y = 4;
            TilePixel.X = 32;
            TilePixel.Y = 32;

            TileSize.X = TileSize.X * TilePixel.X;
            TileSize.Y = TileSize.Y * TilePixel.Y;

            tilewidthbox.Value = TileSize.X;
            tileheightbox.Value = TileSize.Y;
            tilepixelsbox.Value = TilePixel.X;
            tilespixelbox2.Value = TilePixel.Y;

            panel1.Invalidate();

            // Default Room
            RoomsList.Items.Add("Room " + (int)roomnumberbox.Value + " difficulty: " + (int)difficultybox.Value);
            roomNumber.Add((int)roomnumberbox.Value);
            roomRating.Add((int)difficultybox.Value);
            totalRooms = 1;

            // Default rect
            rect = new Rectangle(0, 0, TilePixel.X, TilePixel.Y);

            // Scroll bars
            {
                TileSize.X = (int)tilewidthbox.Value;
                TileSize.Y = (int)tileheightbox.Value;
                TilePixel.X = (int)tilepixelsbox.Value;
                TilePixel.Y = (int)tilespixelbox2.Value;

                Point offset = Point.Empty;
                offset.X -= tilehbar.Value;
                offset.Y -= tilevbar.Value;

                tilehbar.LargeChange = TilePixel.X;
                tilehbar.SmallChange = TilePixel.X;
                tilevbar.LargeChange = TilePixel.Y;
                tilevbar.SmallChange = TilePixel.Y;

                Point p = new Point(rect.Left, rect.Top);
                while (p.X % TilePixel.X != 0)
                    p.X--;
                while (p.Y % TilePixel.Y != 0)
                    p.Y--;
                rect = new Rectangle(p.X + offset.X, p.Y + offset.Y, TilePixel.X, TilePixel.Y);

                tilevbar.Maximum = TileSize.Y / TilePixel.Y * TilePixel.Y;
                tilehbar.Maximum = TileSize.X / TilePixel.X * TilePixel.X;

                TileSize.X = (int)tilewidthbox.Value / TilePixel.X * TilePixel.X;
                TileSize.Y = (int)tileheightbox.Value / TilePixel.Y * TilePixel.Y;

                tilewidthbox.Value = TileSize.X;
                tileheightbox.Value = TileSize.Y;

                MapPixel.X = TilePixel.X;
                MapPixel.Y = TilePixel.Y;

                mappixelsbox.Value = MapPixel.X;
                mappixelbox2.Value = MapPixel.Y;

                MapSize.X = MapSize.X / MapPixel.X * MapPixel.X;
                MapSize.Y = MapSize.Y / MapPixel.Y * MapPixel.Y;

                mapwidthbox.Value = MapSize.X;
                mapheightbox.Value = MapSize.Y;


                panel1.Invalidate();
            }
            {
                MapSize.X = (int)mapwidthbox.Value;
                MapSize.Y = (int)mapheightbox.Value;
                MapPixel.X = (int)mappixelsbox.Value;
                MapPixel.Y = (int)mappixelbox2.Value;

                Point offset = Point.Empty;
                offset.X -= maphbar.Value;
                offset.Y -= mapvbar.Value;

                maphbar.LargeChange = MapPixel.X;
                maphbar.SmallChange = MapPixel.X;
                mapvbar.LargeChange = MapPixel.Y;
                mapvbar.SmallChange = MapPixel.Y;

                for (int i = 0; i < TilesList.Items.Count; ++i)
                {
                    TilesList.SelectedIndex = i;
                    if (TilesList.SelectedIndex != -1 && (positon[i].X > MapSize.X * MapPixel.X - MapPixel.X || positon[i].Y > MapSize.Y * MapPixel.Y - MapPixel.Y))
                    {
                        tileGraphics.RemoveAt(TilesList.SelectedIndex);
                        tileLeftTop.RemoveAt(TilesList.SelectedIndex);
                        tileRec.RemoveAt(TilesList.SelectedIndex);
                        positon.RemoveAt(TilesList.SelectedIndex);
                        tileTypes.RemoveAt(TilesList.SelectedIndex);
                        tileRoomNumbers.RemoveAt(TilesList.SelectedIndex);
                        TilesList.Items.RemoveAt(TilesList.SelectedIndex);
                        TilesList.SelectedIndex = -1;
                        i = -1;
                    }
                }

                mapvbar.Maximum = MapSize.Y / MapPixel.Y * MapPixel.Y;
                maphbar.Maximum = MapSize.X / MapPixel.X * MapPixel.X;

                MapSize.X = (int)mapwidthbox.Value / MapPixel.X * MapPixel.X;
                MapSize.Y = (int)mapheightbox.Value / MapPixel.Y * MapPixel.Y;

                mapwidthbox.Value = MapSize.X;
                mapheightbox.Value = MapSize.Y;

                TilePixel.X = MapPixel.X;
                TilePixel.Y = MapPixel.Y;

                tilepixelsbox.Value = TilePixel.X;
                tilespixelbox2.Value = TilePixel.Y;

                TileSize.X = TileSize.X / TilePixel.X * TilePixel.X;
                TileSize.Y = TileSize.Y / TilePixel.Y * TilePixel.Y;

                tilewidthbox.Value = TileSize.X;
                tileheightbox.Value = TileSize.Y;

                panel2.Invalidate();
            }
        }

        public void CloseThis(object sender, EventArgs e)
        {
            run = false;
        }

        public void Render()
        {
            // Graphics panel 1
            SGP.ManagedDirect3D.Instance.Clear(panel2, panel2.BackColor);
            SGP.ManagedDirect3D.Instance.DeviceBegin();
            SGP.ManagedDirect3D.Instance.SpriteBegin();

            Point offset = Point.Empty;
            offset.X -= maphbar.Value;
            offset.Y -= mapvbar.Value;

            for (int i = 0; i < positon.Count; ++i)
            {
                if (tileTypes[i] == 1 && tilesetpicture != -1) // Background
                {
                    SGP.ManagedTextureManager.Instance.Draw(tilesetpicture, positon[i].X + offset.X, positon[i].Y + offset.Y, 1.0f, 1.0f, tileRec[i], 0, 0, 0.0f, 0);
                    SGP.ManagedDirect3D.Instance.Sprite.Flush();
                }
            }
            for (int i = 0; i < positon.Count; ++i)
            {
                if (tileTypes[i] == 3) // Trigger
                {
                    Rectangle rectang = new Rectangle(positon[i].X + offset.X + 4, positon[i].Y + offset.Y, 4, 4);
                    SGP.ManagedDirect3D.Instance.DrawRect(rectang, Color.Yellow);
                }
                else if (tileTypes[i] == 2) // Collision
                {
                    Rectangle rectang = new Rectangle(positon[i].X + offset.X, positon[i].Y + offset.Y, 4, 4);
                    SGP.ManagedDirect3D.Instance.DrawRect(rectang, Color.Red);
                }
                else if (tileTypes[i] == 4) // SpawnPoint
                {
                    Rectangle rectang = new Rectangle(positon[i].X + offset.X, positon[i].Y + offset.Y+4, 4, 4);
                    SGP.ManagedDirect3D.Instance.DrawRect(rectang, Color.Blue);
                }
             }

            SGP.ManagedDirect3D.Instance.Sprite.Flush();

            for (int i = 0; i < MapSize.X/MapPixel.X; ++i)
            {
                for (int j = 0; j < MapSize.Y/MapPixel.Y; ++j)
                {
                    Rectangle r = new Rectangle(i * MapPixel.X + offset.X, j * MapPixel.Y + offset.Y, MapPixel.X, MapPixel.Y);
                    SGP.ManagedDirect3D.Instance.DrawEmptyRect(r, Color.Black, 1.0f);
                }
            }

            SGP.ManagedDirect3D.Instance.SpriteEnd();
            SGP.ManagedDirect3D.Instance.DeviceEnd();
            SGP.ManagedDirect3D.Instance.Present(panel2);

            // Graphics Panel 2
            SGP.ManagedDirect3D.Instance.Clear(panel1, panel1.BackColor);
            SGP.ManagedDirect3D.Instance.DeviceBegin();
            SGP.ManagedDirect3D.Instance.SpriteBegin();

            offset = Point.Empty;
            offset.X -= tilehbar.Value;
            offset.Y -= tilevbar.Value;

            if (tilesetpicture != -1)
                SGP.ManagedTextureManager.Instance.Draw(tilesetpicture, 0 + offset.X, 0 + offset.Y, 1.0f, 1.0f, Rectangle.Empty, 0, 0, 0.0f, 0);

            SGP.ManagedDirect3D.Instance.Sprite.Flush();

            for (int i = 0; i < TileSize.X/TilePixel.X; ++i)
            {
                for(int j = 0; j < TileSize.Y/TilePixel.Y; ++j)
                {
                    Rectangle r = new Rectangle(i * TilePixel.X + offset.X, j * TilePixel.Y + offset.Y, TilePixel.X, TilePixel.Y);
                    SGP.ManagedDirect3D.Instance.DrawEmptyRect(r, Color.Black, 1.0f);
                }
            }

            Rectangle redbox = new Rectangle(left+offset.X, top+offset.Y, TilePixel.X, TilePixel.Y);
            SGP.ManagedDirect3D.Instance.DrawEmptyRect(redbox, Color.Red, 1.0f);
           
            SGP.ManagedDirect3D.Instance.SpriteEnd();
            SGP.ManagedDirect3D.Instance.DeviceEnd();
            SGP.ManagedDirect3D.Instance.Present(panel1);
        }

        private void Wall_Click(object sender, EventArgs e)
        {
            Floor.Enabled = true;
            Door.Enabled = true;
            Wall.Enabled = false; 
            SpawnPoint.Enabled = true;

            currentTileType = 2;
        }

        private void Floor_Click(object sender, EventArgs e)
        {
            Floor.Enabled = false;
            Door.Enabled = true;
            Wall.Enabled = true;
            SpawnPoint.Enabled = true;

            currentTileType = 1;
        }

        private void Door_Click(object sender, EventArgs e)
        {
            Floor.Enabled = true;
            Door.Enabled = false;
            Wall.Enabled = true;
            SpawnPoint.Enabled = true;

            currentTileType = 3;
        }

        private void SpawnPoint_Click(object sender, EventArgs e)
        {
            Floor.Enabled = true;
            Door.Enabled = true;
            Wall.Enabled = true;
            SpawnPoint.Enabled = false;

            currentTileType = 4;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            run = false;
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Reset room number to 0
            roomnumberbox.Value = 0;

            // Clear the lists
            positon.Clear();
            tileTypes.Clear();
            tileRoomNumbers.Clear();
            tileRec.Clear();
            tileGraphics.Clear();
            tileLeftTop.Clear();
            TilesList.Items.Clear();

            // Rooms Clearing
            roomNumber.Clear();
            roomRating.Clear();
            RoomsList.Items.Clear();
            RoomsList.Items.Add("Room " + (int)roomnumberbox.Value + " difficulty: " + (int)difficultybox.Value);
            roomNumber.Add((int)roomnumberbox.Value);
            roomRating.Add((int)difficultybox.Value);
            totalRooms = 1;

            // Set the floor as default tile
            Floor.Enabled = false;
            Door.Enabled = true;
            Wall.Enabled = true;
            SpawnPoint.Enabled = true;

            currentTileType = 1;

            // Set map back to 10x10 with 32 pixels
            MapSize.X = 10;
            MapSize.Y = 10;
            MapPixel.X = 32;
            MapPixel.Y = 32;

            MapSize.X = MapSize.X * MapPixel.X;
            MapSize.Y = MapSize.Y * MapPixel.Y;

            mapwidthbox.Value = MapSize.X;
            mapheightbox.Value = MapSize.Y;
            mappixelsbox.Value = MapPixel.X;
            mappixelbox2.Value = MapPixel.Y;

            panel2.Invalidate();

            // Set Tiles back to 4x4 with 32 pixels
            TileSize.X = 4;
            TileSize.Y = 4;
            TilePixel.X = 32;
            TilePixel.Y = 32;

            TileSize.X = TileSize.X * TilePixel.X;
            TileSize.Y = TileSize.Y * TilePixel.Y;

            tilewidthbox.Value = TileSize.X;
            tileheightbox.Value = TileSize.Y;
            tilepixelsbox.Value = TilePixel.X;
            tilespixelbox2.Value = TilePixel.Y;

            rect = new Rectangle(0, 0, TilePixel.X, TilePixel.Y);

            panel1.Invalidate();

            left = 0;
            top = 0;
            graphicString = "";
            tilesetpicture = -1;

            tilehbar.Maximum = 100;
            tilevbar.Maximum = 100;
            maphbar.Maximum = 100;
            mapvbar.Maximum = 100;
        }

        public void clearAll()
        {
            // Reset room to 0
            roomnumberbox.Value = 0;

            // Clear the lists
            positon.Clear();
            tileTypes.Clear();
            tileRoomNumbers.Clear();
            tileRec.Clear();
            tileGraphics.Clear();
            tileLeftTop.Clear();
            TilesList.Items.Clear();

            // Rooms Clearing
            roomNumber.Clear();
            roomRating.Clear();
            RoomsList.Items.Clear();
            totalRooms = 0;

            // Set the floor as default tile
            Floor.Enabled = false;
            Door.Enabled = true;
            Wall.Enabled = true;
            SpawnPoint.Enabled = true;

            currentTileType = 1;

            // Set map back to 10x10 with 32 pixels
            MapSize.X = 10;
            MapSize.Y = 10;
            MapPixel.X = 32;
            MapPixel.Y = 32;

            MapSize.X = MapSize.X * MapPixel.X;
            MapSize.Y = MapSize.Y * MapPixel.Y;

            mapwidthbox.Value = MapSize.X;
            mapheightbox.Value = MapSize.Y;
            mappixelsbox.Value = MapPixel.X;
            mappixelbox2.Value = MapPixel.Y;

            panel2.Invalidate();

            // Set Tiles back to 4x4 with 32 pixels
            TileSize.X = 4;
            TileSize.Y = 4;
            TilePixel.X = 32;
            TilePixel.Y = 32;

            TileSize.X = TileSize.X * TilePixel.X;
            TileSize.Y = TileSize.Y * TilePixel.Y;

            tilewidthbox.Value = TileSize.X;
            tileheightbox.Value = TileSize.Y;
            tilepixelsbox.Value = TilePixel.X;
            tilespixelbox2.Value = TilePixel.Y;

            rect = new Rectangle(0, 0, TilePixel.X, TilePixel.Y);

            panel1.Invalidate();

            left = 0;
            top = 0;
            graphicString = "";
            tilesetpicture = -1;

            tilehbar.Maximum = 100;
            tilevbar.Maximum = 100;
            maphbar.Maximum = 100;
            mapvbar.Maximum = 100;
        }

        private void applymap_Click(object sender, EventArgs e)
        {
            MapSize.X = (int)mapwidthbox.Value;
            MapSize.Y = (int)mapheightbox.Value;
            MapPixel.X = (int)mappixelsbox.Value;
            MapPixel.Y = (int)mappixelbox2.Value;

            Point offset = Point.Empty;
            offset.X -= maphbar.Value;
            offset.Y -= mapvbar.Value;

            maphbar.LargeChange = MapPixel.X;
            maphbar.SmallChange = MapPixel.X;
            mapvbar.LargeChange = MapPixel.Y;
            mapvbar.SmallChange = MapPixel.Y;

            for (int i = 0; i < TilesList.Items.Count; ++i)
            {
                TilesList.SelectedIndex = i;
                if (TilesList.SelectedIndex != -1 && (positon[i].X >= MapSize.X || positon[i].Y >= MapSize.Y))
                {
                    tileGraphics.RemoveAt(TilesList.SelectedIndex);
                    tileLeftTop.RemoveAt(TilesList.SelectedIndex);
                    tileRec.RemoveAt(TilesList.SelectedIndex);
                    positon.RemoveAt(TilesList.SelectedIndex);
                    tileTypes.RemoveAt(TilesList.SelectedIndex);
                    tileRoomNumbers.RemoveAt(TilesList.SelectedIndex);
                    TilesList.Items.RemoveAt(TilesList.SelectedIndex);
                    if (i >= 1)
                    {
                        i -= 1;
                    }
                    else
                    {
                        i = 0;
                    }
                }
            }

            mapvbar.Maximum = MapSize.Y / MapPixel.Y * MapPixel.Y;
            maphbar.Maximum = MapSize.X / MapPixel.X * MapPixel.X;

            MapSize.X = (int)mapwidthbox.Value / MapPixel.X * MapPixel.X;
            MapSize.Y = (int)mapheightbox.Value / MapPixel.Y * MapPixel.Y;

            mapwidthbox.Value = MapSize.X;
            mapheightbox.Value = MapSize.Y;

            TilePixel.X = MapPixel.X;
            TilePixel.Y = MapPixel.Y;

            tilepixelsbox.Value = TilePixel.X;
            tilespixelbox2.Value = TilePixel.Y;

            TileSize.X = TileSize.X / TilePixel.X * TilePixel.X;
            TileSize.Y = TileSize.Y / TilePixel.Y * TilePixel.Y;

            tilewidthbox.Value = TileSize.X;
            tileheightbox.Value = TileSize.Y;

            panel2.Invalidate();
        }

        private void graphicsPanel1_MouseClick(object sender, MouseEventArgs e)
        {
            Point offset = Point.Empty;
            offset.X -= maphbar.Value;
            offset.Y -= mapvbar.Value;

            int x = MapSize.X / MapPixel.X * MapPixel.X;
            int y = MapSize.Y / MapPixel.Y * MapPixel.Y;

            if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Location.X - offset.X < x && e.Location.Y - offset.Y < y)
            {
                Point p = new Point(e.Location.X - offset.X, e.Location.Y - offset.Y);
                while (p.X % MapPixel.X != 0)
                    p.X--;
                while (p.Y % MapPixel.Y != 0)
                    p.Y--;

                bool DontAdd = false;
                if (p.X < 0 || p.Y < 0)
                    DontAdd = true;

                currentPositon = p;

                string TileName = "None";

                if (currentTileType == 1)
                    TileName = "Background";
                else if (currentTileType == 2)
                    TileName = "Collision";
                else if (currentTileType == 3)
                    TileName = "Trigger";
                else if (currentTileType == 4)
                    TileName = "SpawnPoint";

                bool CanAdd = true;

                for(int i = 0; i < positon.Count; ++i)
                    if (currentPositon != positon[i])
                        CanAdd = true;
                    else
                    {
                        if (currentTileType == tileTypes[i])
                        {
                            CanAdd = false;
                            break;
                        }
                        else
                            CanAdd = true;
                    }

                Point lt = new Point(left, top);
                if (CanAdd == true && DontAdd != true)
                {
                    TilesList.Items.Add(TileName + " Room: " + (int)roomnumberbox.Value + " " + currentPositon);
                    positon.Add(currentPositon);
                    tileTypes.Add(currentTileType);
                    tileRoomNumbers.Add((int)roomnumberbox.Value);
                    tileRec.Add(rect);
                    if(currentTileType == 3)
                        tileGraphics.Add(triggerstringbox.Text);
                    else
                        tileGraphics.Add(graphicString);
                    tileLeftTop.Add(lt);
                }

                //panel2.Invalidate();
            }
            
            // Right click to remove
            if (e.Button == System.Windows.Forms.MouseButtons.Right && e.Location.X - offset.X < x && e.Location.Y - offset.Y < y)
            {
                Point pd = new Point(e.Location.X - offset.X, e.Location.Y - offset.Y);
                while (pd.X % MapPixel.X != 0)
                    pd.X--;
                while (pd.Y % MapPixel.Y != 0)
                    pd.Y--;

                for (int i = 0; i < positon.Count; ++i)
                {
                    if (positon[i] == pd)
                    {
                        TilesList.Items.RemoveAt(i);
                        positon.RemoveAt(i);
                        tileTypes.RemoveAt(i);
                        tileRoomNumbers.RemoveAt(i);
                        tileRec.RemoveAt(i);
                        tileGraphics.RemoveAt(i);
                        tileLeftTop.RemoveAt(i);
                        i = 0;
                    }
                }
            }
        }

        private void RemoveTile_Click(object sender, EventArgs e)
        {
            if (TilesList.SelectedIndex != -1)
            {
                tileGraphics.RemoveAt(TilesList.SelectedIndex);
                tileLeftTop.RemoveAt(TilesList.SelectedIndex);
                tileRec.RemoveAt(TilesList.SelectedIndex);
                positon.RemoveAt(TilesList.SelectedIndex);
                tileTypes.RemoveAt(TilesList.SelectedIndex);
                tileRoomNumbers.RemoveAt(TilesList.SelectedIndex);
                TilesList.Items.RemoveAt(TilesList.SelectedIndex);
                TilesList.SelectedIndex = -1;
            }
        }

        private void graphicsPanel1_MouseMove(object sender, MouseEventArgs e)
        {
            Point offset = Point.Empty;
            offset.X -= maphbar.Value;
            offset.Y -= mapvbar.Value;

            int x = MapSize.X / MapPixel.X * MapPixel.X;
            int y = MapSize.Y / MapPixel.Y * MapPixel.Y;

            if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Location.X - offset.X < x && e.Location.Y - offset.Y < y)
            {
                Point p = new Point(e.Location.X - offset.X, e.Location.Y - offset.Y);
                while (p.X % MapPixel.X != 0)
                    p.X--;
                while (p.Y % MapPixel.Y != 0)
                    p.Y--;

                bool DontAdd = false;
                if (p.X < 0 || p.Y < 0)
                    DontAdd = true;

                currentPositon = p;

                string TileName = "None";

                if (currentTileType == 1)
                    TileName = "Background";
                else if (currentTileType == 2)
                    TileName = "Collision";
                else if (currentTileType == 3)
                    TileName = "Trigger";
                else if (currentTileType == 4)
                    TileName = "SpawnPoint";

                bool CanAdd = true;

                for (int i = 0; i < positon.Count; ++i)
                    if (currentPositon != positon[i])
                        CanAdd = true;
                    else
                    {
                        if (currentTileType == tileTypes[i])
                        {
                            CanAdd = false;
                            break;
                        }
                        else
                            CanAdd = true;
                    }

                Point lt = new Point(left, top);
                if (CanAdd == true && DontAdd != true)
                {
                    TilesList.Items.Add(TileName + " Room: " + (int)roomnumberbox.Value + " " + currentPositon);
                    positon.Add(currentPositon);
                    tileTypes.Add(currentTileType);
                    tileRoomNumbers.Add((int)roomnumberbox.Value);
                    tileRec.Add(rect);
                    if (currentTileType == 3)
                        tileGraphics.Add(triggerstringbox.Text);
                    else
                        tileGraphics.Add(graphicString);
                    tileLeftTop.Add(lt);
                }

                //panel2.Invalidate();
            }

            // Right click to remove
            if (e.Button == System.Windows.Forms.MouseButtons.Right && e.Location.X - offset.X < x && e.Location.Y - offset.Y < y)
            {
                Point pd = new Point(e.Location.X - offset.X, e.Location.Y - offset.Y);
                while (pd.X % MapPixel.X != 0)
                    pd.X--;
                while (pd.Y % MapPixel.Y != 0)
                    pd.Y--;

                for (int i = 0; i < positon.Count; ++i)
                {
                    if (positon[i] == pd)
                    {
                        TilesList.Items.RemoveAt(i);
                        positon.RemoveAt(i);
                        tileTypes.RemoveAt(i);
                        tileRoomNumbers.RemoveAt(i);
                        tileRec.RemoveAt(i);
                        tileGraphics.RemoveAt(i);
                        tileLeftTop.RemoveAt(i);
                        i = 0;
                    }
                }
            }
        }

        private void applytiles_Click(object sender, EventArgs e)
        {
            TileSize.X = (int)tilewidthbox.Value;
            TileSize.Y = (int)tileheightbox.Value;
            TilePixel.X = (int)tilepixelsbox.Value;
            TilePixel.Y = (int)tilespixelbox2.Value;

            Point offset = Point.Empty;
            offset.X -= tilehbar.Value;
            offset.Y -= tilevbar.Value;

            tilehbar.LargeChange = TilePixel.X;
            tilehbar.SmallChange = TilePixel.X;
            tilevbar.LargeChange = TilePixel.Y;
            tilevbar.SmallChange = TilePixel.Y;

            Point p = new Point(rect.Left, rect.Top);
            while (p.X % TilePixel.X != 0)
                p.X--;
            while (p.Y % TilePixel.Y != 0)
                p.Y--;
            rect = new Rectangle(p.X + offset.X, p.Y + offset.Y, TilePixel.X, TilePixel.Y);

            tilevbar.Maximum = TileSize.Y / TilePixel.Y * TilePixel.Y;
            tilehbar.Maximum = TileSize.X / TilePixel.X * TilePixel.X;

            TileSize.X = (int)tilewidthbox.Value / TilePixel.X * TilePixel.X;
            TileSize.Y = (int)tileheightbox.Value / TilePixel.Y * TilePixel.Y;
            
            tilewidthbox.Value = TileSize.X;
            tileheightbox.Value = TileSize.Y;

            MapPixel.X = TilePixel.X;
            MapPixel.Y = TilePixel.Y;

            mappixelsbox.Value = MapPixel.X;
            mappixelbox2.Value = MapPixel.Y;

            MapSize.X = MapSize.X / MapPixel.X * MapPixel.X;
            MapSize.Y = MapSize.Y / MapPixel.Y * MapPixel.Y;
           
            mapwidthbox.Value = MapSize.X;
            mapheightbox.Value = MapSize.Y;
            

            panel1.Invalidate();
        }

        private void RoomsUpdate_Click(object sender, EventArgs e)
        {
            if (RoomsList.SelectedIndex != -1)
            {
                RoomsList.Items[RoomsList.SelectedIndex] = ("Room " + (int)roomNumber[RoomsList.SelectedIndex] + " difficulty: " + (int)difficultybox.Value);
                roomRating[RoomsList.SelectedIndex] = (int)difficultybox.Value;
                RoomsList.SelectedIndex = -1;
            }
        }

        private void roomnumberbox_ValueChanged(object sender, EventArgs e)
        {
            bool AddRoom = true;

            for (int i = 0; i < totalRooms; ++i)
            {
                if (roomNumber[i] != (int)roomnumberbox.Value)
                    AddRoom = true;
                else
                {
                    AddRoom = false;
                    break;
                }
            }

            if (AddRoom == true)
            {
                RoomsList.Items.Add("Room " + (int)roomnumberbox.Value + " difficulty: " + (int)difficultybox.Value);
                roomNumber.Add((int)roomnumberbox.Value);
                roomRating.Add((int)difficultybox.Value);
                totalRooms++;
            }
        }

        private void loadTileSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (DialogResult.OK == dlg.ShowDialog())
            {
                tilesetpicture = SGP.ManagedTextureManager.Instance.LoadTexture(dlg.FileName, 0);

                int count = dlg.FileName.Length-1;
                string str = "";
                while (dlg.FileName[count] != '\\')
                {
                    str += dlg.FileName[count];
                    count--;
                }
                for (int i = str.Length-1; i >= 0; --i)
                    graphicString += str[i];
                for (int i = 0; i < tileGraphics.Count; ++i)
                    if(tileTypes[i] != 3)
                        tileGraphics[i] = graphicString;
            }
        }

        private void graphicsPanel2_MouseClick(object sender, MouseEventArgs e)
        {
            Point offset = Point.Empty;
            offset.X -= tilehbar.Value;
            offset.Y -= tilevbar.Value;

            int y = TileSize.Y / TilePixel.Y * TilePixel.Y;
            int x = TileSize.X / TilePixel.X * TilePixel.X;

            if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Location.X - offset.X < x && e.Location.Y - offset.Y < y)
            {
                Point p = new Point(e.Location.X - offset.X, e.Location.Y - offset.Y);
                while (p.X % TilePixel.X != 0)
                    p.X--;
                while (p.Y % TilePixel.Y != 0)
                    p.Y--;

                bool DontAdd = false;
                if (p.X < 0 || p.Y < 0)
                    DontAdd = true;

                if (DontAdd == false)
                {
                    rect = new Rectangle(p.X, p.Y, TilePixel.X, TilePixel.Y);
                    left = p.X;
                    top = p.Y;
                }

                //panel1.Invalidate();
            }
        }

        private void setToolStripMenuItem_Click(object sender, EventArgs e)
        {
             FolderBrowserDialog dlg = new FolderBrowserDialog();

             if (DialogResult.OK == dlg.ShowDialog())
             {
                 workspace = dlg.SelectedPath + "\\";
             }
        }

        private void resetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            workspace = "";
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Create a size file dialog
            SaveFileDialog dlg = new SaveFileDialog();
            // Set the filter strings
            dlg.Filter = "All Files(*.*)|*.*|My Files(*.xml)|*.xml";
            // Set the default extension
            dlg.DefaultExt = "xml";
            // Display the dialog to the user
            if (DialogResult.OK == dlg.ShowDialog())
            {
                // Get String
                string str = "";
                int count = dlg.FileName.Length-1;
                while (dlg.FileName[count] != '\\')
                {
                    str += dlg.FileName[count];
                    count--;
                }
                string send = "";
                if (workspace == "")
                    str = dlg.FileName;
                else
                    send = workspace;
                string savespace = "";
                for (int i = dlg.FileName.Length - 5; i > 0; --i)
                    if (dlg.FileName[i] != '\\')
                        savespace += dlg.FileName[i];
                    else
                        break;
                for (int i = savespace.Length - 1; i >= 0; --i)
                    send += savespace[i];
                // Save Options
                saveOptions(send);
                // Open a stream for writing
                System.IO.StreamWriter writer = new System.IO.StreamWriter(send + ".xml");
                // Write the string
                writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                writer.WriteLine("<level_info>");
                for (int i = 0; i < totalRooms; ++i)
                {
                    writer.WriteLine("         <Room number = \"" + roomNumber[i] + "\" rating = \"" + roomRating[i] + "\"/>");
                    for (int j = 0; j < tileTypes.Count; ++j)
                    {
                        if (tileRoomNumbers[j] == i)
                        {
                            if(tileTypes[j] != 3)
                                writer.WriteLine("         <Tile type = \"" + tileTypes[j] + "\" roomnum = \"" + tileRoomNumbers[j] + "\" x = \"" + positon[j].X + "\" y = \"" + positon[j].Y + "\" width = \"" + TilePixel.X + "\" height = \"" + TilePixel.Y + "\" left = \"" + tileLeftTop[j].X + "\" top = \"" + tileLeftTop[j].Y + "\" right = \"" + tileRec[j].Right + "\" bottom = \"" + tileRec[j].Bottom + "\">" + graphicString + "</Tile>");
                            else
                                writer.WriteLine("         <Tile type = \"" + tileTypes[j] + "\" roomnum = \"" + tileRoomNumbers[j] + "\" x = \"" + positon[j].X + "\" y = \"" + positon[j].Y + "\" width = \"" + TilePixel.X + "\" height = \"" + TilePixel.Y + "\" left = \"" + tileLeftTop[j].X + "\" top = \"" + tileLeftTop[j].Y + "\" right = \"" + tileRec[j].Right + "\" bottom = \"" + tileRec[j].Bottom + "\">" + tileGraphics[j] + "</Tile>");
                        }
                    }
                }
                writer.WriteLine("</level_info>");
                // Close the stream
                writer.Close();
            }
        }

        private void saveOptions(string recieve)
        {
            // Create a size file dialog
            SaveFileDialog dlgO = new SaveFileDialog();
            // Set the filter strings
            dlgO.Filter = "All Files(*.*)|*.*|My Files(*.xml)|*.xml";
            // Set options
            dlgO.FileName = recieve + "_Options.xml";
            // Open a stream for writing
            System.IO.StreamWriter writerO = new System.IO.StreamWriter(dlgO.FileName);
            // Write the string
            writerO.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            writerO.WriteLine("<level_options>");
            writerO.WriteLine("	<RoomCount count = \"" + RoomsList.Items.Count + "\" />");
            writerO.WriteLine("	<TileSet tSet = \"" + graphicString + "\" />");
            writerO.WriteLine("	<TileSettings width = \"" + TileSize.X + "\" " + "height = \"" + TileSize.Y + "\" " + "pixelx = \"" + TilePixel.X + "\" " + "pixely = \"" + TilePixel.Y + "\" />");
            writerO.WriteLine("	<MapSettings width = \"" + MapSize.X + "\" " + "height = \"" + MapSize.Y + "\" " + "pixelx = \"" + MapPixel.X + "\" " + "pixely = \"" + MapPixel.Y + "\" />");
            writerO.WriteLine("</level_options>");
            // Close the stream
            writerO.Close();
        }

        private void instructionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("The Background tiles layer will show which ever tile you have selected from your tile set.\n" +
                            "The Trigger tiles layer will show a yellow square around the top left of the tile.\n" +
                            "The Collision tiles layer will show a red square around the top left of the tile.\n" +
                            "The Spawn Point tiles layer will show a blue square around the top left of the tile.");
        }

        private void tilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To add a room you just increment the Tile Room Number.\n" +
                            "There is no way to remove a room.  The room will get which\n" +
                            "ever difficulty that the room difficulty is on.  If you want\n" +
                            "to change this change the room difficulty, click on the room you\n" +
                            "want to change in the list box and hit update.  All positions are\n" +
                            "game world positions.");
        }

        private void roomsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To add a tile first select a layer, the default is backgound.\n" +
                            "Then load a tile set (in the file menu).  Then you can click, or\n" +
                            "drag the mouse to draw on the map.  To change which tile you are getting\n" +
                            "by selecting a different tile in the Tile Set window.  To remove a tile\n" +
                            "select a tile in the tile list and click remove.  For which room the tile will\n" +
                            "the Tile Room Number must be the number of which room you want.\n" +
                            "For trigger tiles enter a trigger event string or else the event will be empty.");
        }

        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To change your settings go to the Tile or Map settings and when\n" +
                            "you have the settings you want hit apply for either the tile or the map.");
        }

        private void saveLoadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To have a relative path you must select a directory.\n" +
                            "If you do not have a relative path will not work, which\n" +
                            "will cause a crash when loading.");
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Clear all so we can load in a map
            clearAll();

            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "All Files|*.*|Xml Files|*.xml";

            if (DialogResult.OK == dlg.ShowDialog())
            {
                XElement xRoot = XElement.Load(dlg.FileName);
                string options = "";
                for (int i = 0; i <= dlg.FileName.Length - 5; ++i)
                    options += dlg.FileName[i];
                options += "_Options.xml";
                XElement xRootO = XElement.Load(options);

                IEnumerable<XElement> xRooms = xRoot.Elements("Room");
                foreach (XElement xRoom in xRooms)
                {
                    int roomNum = 0;
                    int roomRate = 0;

                    XAttribute ROOMNUM = xRoom.Attribute("number");
                    if (ROOMNUM != null)
                    {
                        roomNum = Convert.ToInt32(ROOMNUM.Value);
                    }

                    XAttribute RATING = xRoom.Attribute("rating");
                    if (RATING != null)
                    {
                        roomRate = Convert.ToInt32(RATING.Value);
                    }

                    RoomsList.Items.Add("Room " + roomNum + " difficulty: " + roomRate);
                    roomNumber.Add(roomNum);
                    roomRating.Add(roomRate);
                    totalRooms++;
                }

                IEnumerable<XElement> xTileSet = xRootO.Elements("TileSet");
                foreach (XElement xTileSetX in xTileSet)
                {
                    XAttribute SET = xTileSetX.Attribute("tSet");
                    if (SET != null)
                    {
                        graphicString = SET.Value;
                    }
                    tilesetpicture = -1;
                    tilesetpicture = SGP.ManagedTextureManager.Instance.LoadTexture(workspace+graphicString, 0);
                }

                IEnumerable<XElement> xTileSettings = xRootO.Elements("TileSettings");
                foreach (XElement xTILEsettings in xTileSettings)
                {
                    int xwidth = 0, xheight = 0;
                    int xpx = 0, xpy = 0;

                    XAttribute W = xTILEsettings.Attribute("width");
                    if (W != null)
                    {
                        xwidth = Convert.ToInt32(W.Value);
                    }

                    XAttribute H = xTILEsettings.Attribute("height");
                    if (H != null)
                    {
                        xheight = Convert.ToInt32(H.Value);
                    }

                    XAttribute PX = xTILEsettings.Attribute("pixelx");
                    if (PX != null)
                    {
                        xpx = Convert.ToInt32(PX.Value);
                    }

                    XAttribute PY = xTILEsettings.Attribute("pixely");
                    if (PY != null)
                    {
                        xpy = Convert.ToInt32(PY.Value);
                    }

                    TileSize.X = xwidth;
                    TileSize.Y = xheight;
                    TilePixel.X = xpx;
                    TilePixel.Y = xpy;

                    tilewidthbox.Value = TileSize.X;
                    tileheightbox.Value = TileSize.Y;
                    tilepixelsbox.Value = TilePixel.X;
                    tilespixelbox2.Value = TilePixel.Y;

                    tilevbar.Maximum = TileSize.Y * TilePixel.Y;
                    tilehbar.Maximum = TileSize.X * TilePixel.X;
                }

                IEnumerable<XElement> xMapSettings = xRootO.Elements("MapSettings");
                foreach (XElement xMAPsettings in xMapSettings)
                {
                    int xwidth = 0, xheight = 0;
                    int xpx = 0, xpy = 0;

                    XAttribute W = xMAPsettings.Attribute("width");
                    if (W != null)
                    {
                        xwidth = Convert.ToInt32(W.Value);
                    }

                    XAttribute H = xMAPsettings.Attribute("height");
                    if (H != null)
                    {
                        xheight = Convert.ToInt32(H.Value);
                    }

                    XAttribute PX = xMAPsettings.Attribute("pixelx");
                    if (PX != null)
                    {
                        xpx = Convert.ToInt32(PX.Value);
                    }

                    XAttribute PY = xMAPsettings.Attribute("pixely");
                    if (PY != null)
                    {
                        xpy = Convert.ToInt32(PY.Value);
                    }

                    MapSize.X = xwidth;
                    MapSize.Y = xheight;
                    MapPixel.X = xpx;
                    MapPixel.Y = xpy;

                    mapwidthbox.Value = MapSize.X;
                    mapheightbox.Value = MapSize.Y;
                    mappixelsbox.Value = MapPixel.X;
                    mappixelbox2.Value = MapPixel.Y;

                    mapvbar.Maximum = MapSize.Y * MapPixel.Y;
                    maphbar.Maximum = MapSize.X * MapPixel.X;
                }

                IEnumerable<XElement> xTiles = xRoot.Elements("Tile");
                foreach (XElement xTile in xTiles)
                {
                    int tType = 0;
                    int tX = 0, tY = 0;
                    int tWidth = 0, tHeight = 0;
                    int tLeft = 0, tTop = 0;
                    int tRight = 0, tBottom = 0;
                    int tRoom = 0;

                    XAttribute TYPE = xTile.Attribute("type");
                    if (TYPE != null)
                    {
                        tType = Convert.ToInt32(TYPE.Value);
                    }

                    XAttribute RNUM = xTile.Attribute("roomnum");
                    if (RNUM != null)
                    {
                        tRoom = Convert.ToInt32(RNUM.Value);
                    }

                    XAttribute X = xTile.Attribute("x");
                    if (X != null)
                    {
                        tX = Convert.ToInt32(X.Value);
                    }

                    XAttribute Y = xTile.Attribute("y");
                    if (Y != null)
                    {
                        tY = Convert.ToInt32(Y.Value);
                    }

                    XAttribute WIDTH = xTile.Attribute("width");
                    if (WIDTH != null)
                    {
                        tWidth = Convert.ToInt32(WIDTH.Value);
                    }

                    XAttribute HEIGHT = xTile.Attribute("height");
                    if (HEIGHT != null)
                    {
                        tHeight = Convert.ToInt32(HEIGHT.Value);
                    }

                    XAttribute LEFT = xTile.Attribute("left");
                    if (LEFT != null)
                    {
                        tLeft = Convert.ToInt32(LEFT.Value);
                    }

                    XAttribute TOP = xTile.Attribute("top");
                    if (TOP != null)
                    {
                        tTop = Convert.ToInt32(TOP.Value);
                    }

                    XAttribute RIGHT = xTile.Attribute("right");
                    if (RIGHT != null)
                    {
                        tRight = Convert.ToInt32(RIGHT.Value);
                    }

                    XAttribute BOTTOM = xTile.Attribute("bottom");
                    if (BOTTOM != null)
                    {
                        tBottom = Convert.ToInt32(BOTTOM.Value);
                    }

                    string TileName = "None";

                    if (tType == 1)
                        TileName = "Background";
                    else if (tType == 2)
                        TileName = "Collision";
                    else if (tType == 3)
                        TileName = "Trigger";
                    else if (tType == 4)
                        TileName = "SpawnPoint";

                    currentPositon.X = tX;
                    currentPositon.Y = tY;

                    Point lt = new Point(tLeft, tTop);

                    TilesList.Items.Add(TileName + " Room: " + tRoom + " " + currentPositon);
                    positon.Add(currentPositon);
                    tileTypes.Add(tType);
                    tileRoomNumbers.Add(tRoom);
                    Rectangle Lrect = new Rectangle(tLeft, tTop, tWidth, tHeight);
                    tileRec.Add(Lrect);
                    tileGraphics.Add(workspace+graphicString);
                    tileLeftTop.Add(lt);
                }

                panel2.Invalidate();
                panel1.Invalidate();

                // Scroll bars
                {
                    TileSize.X = (int)tilewidthbox.Value;
                    TileSize.Y = (int)tileheightbox.Value;
                    TilePixel.X = (int)tilepixelsbox.Value;
                    TilePixel.Y = (int)tilespixelbox2.Value;

                    Point offset = Point.Empty;
                    offset.X -= tilehbar.Value;
                    offset.Y -= tilevbar.Value;

                    tilehbar.LargeChange = TilePixel.X;
                    tilehbar.SmallChange = TilePixel.X;
                    tilevbar.LargeChange = TilePixel.Y;
                    tilevbar.SmallChange = TilePixel.Y;

                    Point p = new Point(rect.Left, rect.Top);
                    while (p.X % TilePixel.X != 0)
                        p.X--;
                    while (p.Y % TilePixel.Y != 0)
                        p.Y--;
                    rect = new Rectangle(p.X + offset.X, p.Y + offset.Y, TilePixel.X, TilePixel.Y);

                    tilevbar.Maximum = TileSize.Y / TilePixel.Y * TilePixel.Y;
                    tilehbar.Maximum = TileSize.X / TilePixel.X * TilePixel.X;

                    TileSize.X = (int)tilewidthbox.Value / TilePixel.X * TilePixel.X;
                    TileSize.Y = (int)tileheightbox.Value / TilePixel.Y * TilePixel.Y;

                    tilewidthbox.Value = TileSize.X;
                    tileheightbox.Value = TileSize.Y;

                    MapPixel.X = TilePixel.X;
                    MapPixel.Y = TilePixel.Y;

                    mappixelsbox.Value = MapPixel.X;
                    mappixelbox2.Value = MapPixel.Y;

                    MapSize.X = MapSize.X / MapPixel.X * MapPixel.X;
                    MapSize.Y = MapSize.Y / MapPixel.Y * MapPixel.Y;

                    mapwidthbox.Value = MapSize.X;
                    mapheightbox.Value = MapSize.Y;


                    panel1.Invalidate();
                }
                {
                    MapSize.X = (int)mapwidthbox.Value;
                    MapSize.Y = (int)mapheightbox.Value;
                    MapPixel.X = (int)mappixelsbox.Value;
                    MapPixel.Y = (int)mappixelbox2.Value;

                    Point offset = Point.Empty;
                    offset.X -= maphbar.Value;
                    offset.Y -= mapvbar.Value;

                    maphbar.LargeChange = MapPixel.X;
                    maphbar.SmallChange = MapPixel.X;
                    mapvbar.LargeChange = MapPixel.Y;
                    mapvbar.SmallChange = MapPixel.Y;

                    for (int i = 0; i < TilesList.Items.Count; ++i)
                    {
                        TilesList.SelectedIndex = i;
                        if (TilesList.SelectedIndex != -1 && (positon[i].X > MapSize.X * MapPixel.X - MapPixel.X || positon[i].Y > MapSize.Y * MapPixel.Y - MapPixel.Y))
                        {
                            tileGraphics.RemoveAt(TilesList.SelectedIndex);
                            tileLeftTop.RemoveAt(TilesList.SelectedIndex);
                            tileRec.RemoveAt(TilesList.SelectedIndex);
                            positon.RemoveAt(TilesList.SelectedIndex);
                            tileTypes.RemoveAt(TilesList.SelectedIndex);
                            tileRoomNumbers.RemoveAt(TilesList.SelectedIndex);
                            TilesList.Items.RemoveAt(TilesList.SelectedIndex);
                            TilesList.SelectedIndex = -1;
                            i = -1;
                        }
                    }

                    mapvbar.Maximum = MapSize.Y / MapPixel.Y * MapPixel.Y;
                    maphbar.Maximum = MapSize.X / MapPixel.X * MapPixel.X;

                    MapSize.X = (int)mapwidthbox.Value / MapPixel.X * MapPixel.X;
                    MapSize.Y = (int)mapheightbox.Value / MapPixel.Y * MapPixel.Y;

                    mapwidthbox.Value = MapSize.X;
                    mapheightbox.Value = MapSize.Y;

                    TilePixel.X = MapPixel.X;
                    TilePixel.Y = MapPixel.Y;

                    tilepixelsbox.Value = TilePixel.X;
                    tilespixelbox2.Value = TilePixel.Y;

                    TileSize.X = TileSize.X / TilePixel.X * TilePixel.X;
                    TileSize.Y = TileSize.Y / TilePixel.Y * TilePixel.Y;

                    tilewidthbox.Value = TileSize.X;
                    tileheightbox.Value = TileSize.Y;

                    panel2.Invalidate();
                }
            }
        }

        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To remove one tile select it in the list and hit remove.\n" +
                            "To remove every tile from the position right click.");
        }
    }
}
